<?php

/**
 * Character Limiter
 *
 * Truncates a string to the number of characters specified.
 * Use mb_substr instead of substr to solve problem wwith utf-8
 *
 * @param $str string
 * @param $limit integer
 * @return string
 */
function string_limit($string, $max = 100, $end = '...')
{
    return (mb_strlen($string, 'utf-8') >= $max) ? mb_substr($string, 0, $max, 'utf-8') . $end : $string;
}